<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>添加管理员</title>
    <meta name="author" content="yeshop Team" />
    <meta name="copyright" content="yeshop" />

    <link rel="icon" href="">
    <link href="https://static.9hive.cn/global/vendor/bootstrap-3.3.7/bootstrap.min.css" rel="stylesheet">
    <link href="https://static.9hive.cn/global/vendor/nprogress/nprogress.css" rel="stylesheet">
    <link href="https://static.9hive.cn/global/fonts/font-awesome/font-awesome.min.css" rel="stylesheet">
    <link href="https://static.9hive.cn/global/vendor/icheck/icheck.min.css" rel="stylesheet">
    <link href="https://static.9hive.cn/global/vendor/animate/animate.css" rel="stylesheet">
    <link href="https://static.9hive.cn/global/vendor/bootstrap-table-1.11/bootstrap-table.min.css?v=1.1" rel="stylesheet">
    <link href="https://static.9hive.cn/global/vendor/common/common_20170925.css" rel="stylesheet">
    <link href="https://static.9hive.cn/global/vendor/inside/inside.css?v=1" rel="stylesheet">
    <link href="https://static.9hive.cn/global/vendor/file/file.css" rel="stylesheet">

    <script type="text/javascript" src="/res/js/jquery.js"></script>

    <script type="text/javascript">
        function save() {
            var id=$("input[name='action.id']").val();
            var name=$("input[name='action.name']").val().trim();
            var resourceId=$("input[name='action.resourceId']").val().trim();
            var citySel=$("#citySel").val().trim();
            var img=$("input[name='action.buttonImg']").val();
            var style=$("input[name='action.buttonStyle']").val();
            var link=$("input[name='action.buttonLink']").val();
            if(!name){
                layer.msg("动作名称不允许为空");
                return;
            }
            if(!citySel){
                layer.msg("资源名称不允许为空");
                return;
            }

            $.ajax({
                url: "/shop/action/save",
                type: 'GET',
                data:{
                    "action.name":name,
                    "action.resourceId":resourceId,
                    "action.buttonImg":img,
                    "action.buttonStyle":style,
                    "action.buttonLink":link,
                },
                success: function(data){
                    if(data.code == 1){
                        layer.msg(data.desc);
                    }else if (data.code == 0){
                        window.location.href="/shop/action/list";
                    }
                }});
        }

        function update(){
            var id=$("input[name='action.id']").val();
            var name=$("input[name='action.name']").val().trim();
            var resourceId=$("input[name='action.resourceId']").val().trim();
            var citySel=$("#citySel").val().trim();
            var img=$("input[name='action.buttonImg']").val();
            var style=$("input[name='action.buttonStyle']").val();
            var link=$("input[name='action.buttonLink']").val();
            if(!name){
                layer.msg("动作名称不允许为空");
                return;
            }
            if(!citySel){
                layer.msg("资源名称不允许为空");
                return;
            }
            $.ajax({
                url: "/shop/action/update",
                type: 'GET',
                data:{
                    "action.id":id,
                    "action.name":name,
                    "action.resourceId":resourceId,
                    "action.buttonImg":img,
                    "action.buttonStyle":style,
                    "action.buttonLink":link,
                },
                success: function(data){
                    if(data.code == 1){
                        layer.msg(data.desc);
                    }else if (data.code == 0){
                        window.location.href="/shop/action/list";
                    }
                }});
        }
    </script>
    <script type="text/javascript">
        var setting = {
            check: {
                enable: true,
                chkStyle: "radio",
                radioType: "all"
            },
            view: {
                dblClickExpand: false
            },
            data: {
                simpleData: {
                    enable: true
                }
            },
            callback: {
                onClick: onClick,
                onCheck: onCheck
            },
            async: {
                enable: true,
                url:"/shop/action/resourceTree?actionId=${action.id!}",
                autoParam:["id", "name=n", "level=lv"],
                otherParam:{"otherParam":"zTreeAsyncTest"}
            }
        };

        function onClick(e, treeId, treeNode) {
            var zTree = $.fn.zTree.getZTreeObj("treeDemo");
            zTree.checkNode(treeNode, !treeNode.checked, null, true);
            return false;
        }

        function onCheck(e, treeId, treeNode) {
            var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
                nodes = zTree.getCheckedNodes(true),
                v = "";
            vid="";
            for (var i=0, l=nodes.length; i<l; i++) {
                v += nodes[i].name + ",";
                vid+=nodes[i].id + ',';
            }
            if (v.length > 0 ){
                v = v.substring(0, v.length-1);
                vid=vid.substring(0, vid.length-1);
            }
            var cityObj = $("#citySel");
            var resourceId=$("#resourceId");
            cityObj.attr("value", v);
            resourceId.attr("value",vid);
        }

        function showMenu() {
            var cityObj = $("#citySel");
            var cityOffset = $("#citySel").offset();
            $("#menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");
            $("body").bind("mousedown", onBodyDown);
        }
        function hideMenu() {
            $("#menuContent").fadeOut("fast");
            $("body").unbind("mousedown", onBodyDown);
        }
        function onBodyDown(event) {
            if (!(event.target.id == "menuBtn" || event.target.id == "citySel" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length>0)) {
                hideMenu();
            }
        }

        $(document).ready(function(){
            $.fn.zTree.init($("#treeDemo"), setting);
        });
    </script>
    <%
    var isAdd = false;
    var isEdit = false;
    if(isEmpty(action.id)){
    isAdd = true;
    }else{
    isEdit = true;
    }
    %>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content ibox float-e-margins">
    <div class="ibox-title">
        <div class="pull-left mbx">
            权限管理<span class="line">/</span>
            <a href="/shop/action/list" class="mbxsecond">动作管理</a><span class="line">/</span>
            <span class="current"><%if(isAdd){%>添加角色<%}else{%>编辑角色<%}%></span>
        </div>
    </div>
    <div class="ibox-content">
        <form action="<%if(isAdd){%>/shop/action/save<%}else{%>/shop/action/update<%}%>" method="post" class="form-horizontal form-validate">
            <input type="hidden" name="action.id" value="${action.id!}" />
            <div class="form-group">
                <label class="col-sm-2 control-label">动作名称: </label>
                <div class="col-sm-3">
                    <input type="text" name="action.name" value="${action.name!}" class="form-control input-sm" required="true">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">资源名称: </label>
                <div class="col-sm-3">
                    <input type="hidden" name="action.resourceId" id="resourceId" value="${action.resourceId!}"/>
                    <input type="text" name="" id="citySel" class="form-control input-sm" readonly value="${action.byResourceId.name!}" required="true" onclick="showMenu();"/>
                    <a id="menuBtn" href="#" onclick="showMenu(); return false;">选择</a></li>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-4 col-sm-offset-2">
                    <input type="submit" class="btn btn-primary" value="提交保存" />
                    <button class="btn btn-white" onclick="history.back()" type="button">取消</button>
                </div>
            </div>
            <table class="input" id="showMenuContent" style="height: 300px;">
                <tr>
                    <th style="background-color: white;border-bottom: aliceblue;">
                        <div id="menuContent" class="menuContent" style="display:none; position: absolute;background: #f0f6e4;">
                            <ul id="treeDemo" class="ztree" style="margin-top:0; width:242px; height: 300px;"></ul>
                        </div>
                    </th>
                </tr>
            </table>
        </form>
    </div>
</div>

<script src="https://static.9hive.cn/global/vendor/nprogress/nprogress.js"></script>
<script src="https://static.9hive.cn/global/vendor/bootstrap-3.3.7/bootstrap.min.js"></script>
<script src="https://static.9hive.cn/global/vendor/jquery-validate/jquery.validate.min.js"></script>
<script src="https://static.9hive.cn/global/vendor/jquery-validate/additional-methods.min.js"></script>

<script src="https://static.9hive.cn/global/vendor/jquery-validate/localization/messages_zh.min.js"></script>
<script src="https://static.9hive.cn/global/vendor/jquery-ajaxform/ajax-form.js"></script>
<script src="https://static.9hive.cn/global/vendor/bootstrap-table-1.11/bootstrap-table.min.js"></script>
<script src="https://static.9hive.cn/global/vendor/bootstrap-table/extensions/mobile/bootstrap-table-mobile.min.js"></script>
<script src="https://static.9hive.cn/global/vendor/bootstrap-table-1.11/locale/bootstrap-table-zh-CN.min.js"></script>
<script src="https://static.9hive.cn/global/vendor/layer/layer.js"></script>
<!-- 自定义js -->

<script src="https://static.9hive.cn/global/vendor/inside/inside20170925.js"></script>

<!--ZTREE DEMO-->
<link rel="stylesheet" href="/res/plugins/ztreev3/css/demo.css" type="text/css">
<link rel="stylesheet" href="/res/plugins/ztreev3/css/zTreeStyle/zTreeStyle.css" type="text/css">

<script type="text/javascript" src="/res/plugins/ztreev3/js/jquery.ztree.core.js"></script>
<script type="text/javascript" src="/res/plugins/ztreev3/js/jquery.ztree.excheck.js"></script>
<script type="text/javascript" src="/res/plugins/ztreev3/js/jquery.ztree.exedit.js"></script>
</body>
</html>